/****************************************************************************
*                                                                           *
* sensorrepository.cpp													    *
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/


/****************************************************************************
* Includes										                            *
****************************************************************************/
#include "sensorrepository.h"

void CSensorRepository::init()
{
	getInstance()->clear();
	emit changed();
}

QList<CSensor*>CSensorRepository::toQList()
{
	return (QList<CSensor*>::fromStdList(getInstance()->toList()));
}

std::list<CSensor*>CSensorRepository::toStdList()
{
	return (getInstance()->toList());
}

void CSensorRepository::addSensor(CSensor *pSensor)
{
	assert(pSensor != NULL);
	getInstance()->addItem(pSensor->getUniqueID(), pSensor);
	emit changed();
}

CSensor* CSensorRepository::getSensor(unsigned int nSensorID)
{
	return (getInstance()->getItem(nSensorID));
}

CSensor* CSensorRepository::getSensor(int nPosX, int nPosY)
{
	return (getInstance()->getItem(CSensor::makeUniqueID(nPosX, nPosY)));
}

CSensor* CSensorRepository::getSensor(const QString& qStrName)
{
	iterator it = getInstance()->begin();
	while (it != getInstance()->end())
	{
		if ((*it).second->name() == qStrName)
			return ((*it).second);
		*it++;
	}
	return NULL;
}

QList<QString> CSensorRepository::getQListNames()
{
	QList<QString> qListStrNames;
	iterator it = getInstance()->begin();

	while (it != getInstance()->end())
	{
		qListStrNames.push_back(QString("Name=") + "\"" + (*it).second->name() + "\"" + 
			" x=" + QString::number((*it).second->x()) + 
			" y=" + QString::number((*it).second->y()) +
			" ID=" + QString::number((*it).second->getUniqueID()));
		*it++;
	}
	return qListStrNames;
}

void CSensorRepository::removeSensor(int nPosX, int nPosY)
{
	getInstance()->removeItem(CSensor::makeUniqueID(nPosX, nPosY));	
	emit changed();
}

/****************************************************************************
* End of file																*
****************************************************************************/